package com.share.fastJson;

import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class Student {

    private String name;
    private Integer age;
    private List<Address>  addresses = new ArrayList<>();

    public static void main (String[] args) {
        Student st = new Student();
        st.setName("sunxj");
        st.setAge(26);
        List<Address>  addresses = new ArrayList<>();

        Address address = new Address();
        address.setId(1);
        address.setName("北京");

        Address address1 = new Address();
        address1.setId(2);
        address1.setName("天津");

        addresses.add(address);
        addresses.add(address1);

        String add = JSON.toJSONString(addresses);
        System.out.println(add);

        st.setAddresses(addresses);

        String stStr = JSON.toJSONString(st);
        System.out.println(stStr);

    }
}
